package com.xueke.crawler.service.fillDocInfo;

import com.xueke.crawler.dao.DocInfoMapper;
import com.xueke.crawler.dao.DocRelationMapper;
import com.xueke.crawler.model.DocInfo;
import com.xueke.crawler.model.DocRelation;
import com.xueke.crawler.service.AbstractBaseService;
import com.xueke.crawler.service.Start;
import org.springframework.beans.factory.annotation.Autowired;

import javax.print.Doc;
import java.util.List;

/**
 * Created by weibo on 2017/5/16.
 *
 * @author weibo.qin
 * @version 2017/5/16
 */
public abstract class BaseFillDocInfo extends AbstractBaseService implements Start {


    @Autowired
    private DocRelationMapper docRelationMapper;

    @Autowired
    private DocInfoMapper docInfoMapper;

    @Override
    public void start() {

        int pageSize = 10000;

        for (int i = 0; ; i++) {
            List<DocRelation> list = docRelationMapper.query4FillDocInfo(i * pageSize, pageSize);
            if (list == null || list.isEmpty()) {
                System.out.println("填充题目详细信息完毕！");
                break;
            }
            List<DocInfo> docInfos = queryDocInfo(list);
            if (docInfos == null || docInfos.isEmpty()) {
                return;
            }
            for (DocInfo docInfo : docInfos) {
            	try{
                    docInfoMapper.insertDocInfo(docInfo);
                    docRelationMapper.updateRecordDetailStatus(docInfo.getDocClass());
            	}catch(Exception e){
            		e.printStackTrace();
            	}
            }

        }

    }

    public abstract List<DocInfo> queryDocInfo(List<DocRelation> list);
}
